package com.xcms.filter;

import com.xcms.news.News;
import com.xcms.news.NewsDao;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;
import java.util.List;

public class InitFilter implements Filter {
    public void destroy() {
    }

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        chain.doFilter(req, resp);
    }

    public void init(FilterConfig config) throws ServletException {
        //在初始化的时候获取最新的10条新闻放在Context里面
        ServletContext context = config.getServletContext();
        List<News>  news= NewsDao.getLatestNews();
        context.setAttribute("LatestNews",news);

    }



}
